<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Cadastro de Turma</title>
    </h:head>
    <h:body>
        <ui:include src="../util/menu.xhtml"/>
        
        <br/>      
        
        <p:messages autoUpdate="true" id="msg"/>        
        <h:form id="form">          
            
            <p:confirmDialog global="true">
                <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" 
                    icon="ui-icon-check"/>
                <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" 
                    icon="ui-icon-close"/>
            </p:confirmDialog>                                
            
            
            
            <p:panelGrid columns="2">
                <f:facet name="header">
                    Cadastro de Turmas
                </f:facet>
                
                <p:outputLabel value="Status"/>
                <p:outputLabel value="#{controllerTurmas.status}"/>
                
                <p:outputLabel value="ID"/>
                <p:inputText value="#{controllerTurmas.id}" disabled="true"/>
                
                <p:outputLabel value="Escola"/>
                <p:selectOneMenu id="escola" value="#{controllerTurmas.escola}" required="true" requiredMessage="Campo Escola é obrigatório!" style="width: 400px" disabled="#{controllerTurmas.desabilitaBotao}">
                        
                        <p:ajax update=":form2:tabela"/>
                        <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
                        <f:selectItems value="#{controllerTurmas.retornaEscolas()}" var="escola" itemLabel="#{escola.nome}" itemValue="#{escola.id}"/>                         
                    </p:selectOneMenu>       
                    
                
                <p:outputLabel value="Descrição"/>
                <p:spinner    value="#{controllerTurmas.descricao}" min="1" max="9" required="true" requiredMessage="Campo Descrição é Obrigatório!"/>

                <p:outputLabel value="Turma"/>
                <p:inputText value="#{controllerTurmas.turma}" required="true" requiredMessage="Campo Turma é Obrigatório!" style="width: 400px"/>

                <p:outputLabel value="Tipo de Ensino"/>
                <p:selectOneMenu id="tipo" value="#{controllerTurmas.tipoensina}" required="true" requiredMessage="Campo Tipo de Ensino é obrigatório" style="width: 400px">
                    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
                    <f:selectItem itemLabel="Ensino Fundamental" itemValue="ef"/>
                     <f:selectItem itemLabel="Ensino Médio" itemValue="em"/>
                </p:selectOneMenu>       
                
                <f:facet name="footer">
                    <p:commandButton value="Novo" process="@this" actionListener="#{controllerTurmas.novo()}" update="form"/>
                    <p:commandButton value="Salvar" actionListener="#{controllerTurmas.gravar()}" update=":form2:tabela, form"/>
                </f:facet>                               
                
            </p:panelGrid>                
        </h:form>
        <p:separator/>
        <h:form id="form2">
        <p:dataTable  var="serie" value="#{controllerTurmas.retornaSeries()}"
             paginator="true"
             rows="9"
             id="tabela">
                     
            <p:column headerText="Descrição">
                <p:outputLabel value="#{serie.descricao}"/>
            </p:column>
           
            <p:column headerText="Turma">
                <p:outputLabel value="#{serie.turma}"/>
            </p:column>
            
            <p:column headerText="Tipo Ensino">
                <p:outputLabel value="#{controllerTurmas.converteTipoEnsino(serie.tipoEnsino) }"/>
            </p:column>            
            
            <p:column headerText="Ações">              
                <p:commandButton value="Excluir" action="#{controllerTurmas.excluir(serie.id)}" process="@form,:form2" update="@form,:form2">
                    <p:confirm header="?" message="Deseja Excluir?" icon="ui-icon-alert" />
                </p:commandButton>
                <p:commandButton value="Alterar" actionListener="#{controllerTurmas.atualizar(serie.id)}" process="@form,:form" update=":form"/>
            </p:column>
         </p:dataTable>
            
        </h:form>
        
        
    </h:body>
</html>

